package database;

import java.sql.Connection;
import java.sql.SQLException;

import org.springframework.beans.BeansException;

import database.dao.UserRechargeDao;
import database.pojo.UserRechargeInfo;
import manager.pay.type.PayResultInfo;
import util.JdbcUtils;
import util.MyFactory;

/**
 * 类名:UserRechargeDBServer
 * 描述:操作数据库表UserRecharge的接口
 * @author zk
 * @date 2018-4-20
 * @version 0.0.1
 *
 */
public class UserRechargeDBServer{
	public boolean insertUserRecharge(UserRechargeInfo uInfo) throws SQLException{
		Connection conn = null;
		try{
			conn = MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).getConnection();
			return MyFactory.context.getBean("UserRechargeDao", UserRechargeDao.class).insert(uInfo, conn);
		}finally{
			MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).releaseConnection(conn);
		}
	}

	public boolean isExitOrderSnAndPaySucc(String out_trade_no) throws BeansException, SQLException {
		Connection conn = null;
		try{
			conn = MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).getConnection();
			return MyFactory.context.getBean("UserRechargeDao", UserRechargeDao.class).isExitOrderSnAndPaySucc(out_trade_no, conn);
		}finally{
			MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).releaseConnection(conn);
		}
	}

	public PayResultInfo getPayResultInfo(String outTradeNo) throws BeansException, SQLException {
		Connection conn = null;
		try{
			conn = MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).getConnection();
			return MyFactory.context.getBean("UserRechargeDao", UserRechargeDao.class).getPayResultInfo(outTradeNo, conn);
		}finally{
			MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).releaseConnection(conn);
		}
	}

	public boolean updateUserRecharge(UserRechargeInfo uInfo) throws BeansException, SQLException {
		Connection conn = null;
		try{
			conn = MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).getConnection();
			return MyFactory.context.getBean("UserRechargeDao", UserRechargeDao.class).updateUserRecharge(uInfo, conn);
		}finally{
			MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).releaseConnection(conn);
		}
		
	}

	public int selectUid(String out_trade_no) throws BeansException, SQLException {
		Connection conn = null;
		try{
			conn = MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).getConnection();
			return MyFactory.context.getBean("UserRechargeDao", UserRechargeDao.class).selectUid(out_trade_no, conn);
		}finally{
			MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).releaseConnection(conn);
		}
	}
		
		

}